
using CStock;
using System;
using System.Diagnostics;

using NUnit.Framework;
using TestCases.StockData;

namespace TestCases.Excel
{
	

	/// <summary>Some simple Tests.</summary>
	/// 
	[TestFixture] 
	public class ExcelReaderTest : ProgramContext_TestCases
	{

        CStock.ExcelReader excelReader;
        string excelFileName;

		
        //private const string excelFileName = @"c:\DAX.xls";


        [SetUp]
        public void ExcelReaderTestSetup()
		{
            string applicationPath = this.programContext.Path;

            excelFileName = applicationPath + @"\Simulatation_Simple.xls";
            excelReader = new ExcelReader();
        }
        [Test]
        public void ReadCBook1xls()
        {
            excelReader.Read_C_book1_xls();

        }
        //[Test]
        //public void UpdateQuotesFromExcelOld()
        //{
        //    IDataItems dataItems = excelReader.OLD_GetShares_Quotes_AndSerialize("Shares");
           
        //}
        [Test]
        public void Update_DAX_FromExel()
        {
            string excelFileName = @"c:\DAX.xls";
            if (excelReader.ReadExcelFile_SetDataSet(excelFileName))
            {
                IDataItems dataItems = excelReader.GetDataItems_CreatePortfolio("DAX");
                Debug.Assert(ExcelReader.GetQuotes_And_Serialize(dataItems, programContext.Path));
            }
            //IDataItems dataItems = excelReader.OLD_GetShares_Quotes_AndSerialize("Shares");

        }
        [Test]
        public void Update_DowJones_FromExel()
        {
            string excelFileName = @"c:\DowJones.xls";
            if (excelReader.ReadExcelFile_SetDataSet(excelFileName))
            {
                IDataItems dataItems = excelReader.GetDataItems_CreatePortfolio("DowJones");
                Debug.Assert(dataItems != null);
                Debug.Assert(ExcelReader.GetQuotes_And_Serialize(dataItems, programContext.Path));
            }
            //IDataItems dataItems = excelReader.OLD_GetShares_Quotes_AndSerialize("Shares");

        }
        [Test]
        public void Update_Bonds_FromExel()
        {
            string excelFileName = @"c:\Bonds.xls";
            if (excelReader.ReadExcelFile_SetDataSet(excelFileName))
            {
                IDataItems dataItems = excelReader.GetDataItems_CreatePortfolio("Bonds");
                Debug.Assert(ExcelReader.GetQuotes_And_Serialize(dataItems, programContext.Path));
            }
            //IDataItems dataItems = excelReader.OLD_GetShares_Quotes_AndSerialize("Shares");

        }
        [Test]
        public void CreatePortfolio_DAX_FromExcel()
        {
            string excelFileName = @"c:\DAX.xls";
            if (excelReader.ReadExcelFile_SetDataSet(excelFileName))
            {
                IDataItems dataItems = excelReader.GetDataItems_CreatePortfolio("DAX");
            }
        }

       
        [Test]
        public void GetSingleShareValue_Siemens()
        {
            if( excelReader.ReadExcelFile_SetDataSet(excelFileName))
                excelReader.CreateDataClassAndReadValues("Siemens");
        }
         [Test]
        public void GetPortfolios()
        {

             
            if(excelReader.ReadExcelFile_SetDataSet(excelFileName))
                excelReader.GetPortfolios(programContext.Path);
        }
    

        [Test]
        public void GetTraders()
        {
            if( excelReader.ReadExcelFile_SetDataSet(excelFileName))
                excelReader.GetTraders();


        }
        [Test]
        public void GetOrders()
        {
            IOrders orders ;
            if( excelReader.ReadExcelFile_SetDataSet(excelFileName))
                orders = excelReader.GetOrders();


        }
        [Test]
        public void GetAssets()
        {
            IAssets assets;
            if (excelReader.ReadExcelFile_SetDataSet(excelFileName))
                assets = excelReader.GetAssets();


        }
        [Test]
        public void GetDeposits()
        {
            IDeposits deposits ;
            if (excelReader.ReadExcelFile_SetDataSet(excelFileName))
                deposits = excelReader.GetDeposits();


        }
        [Test]
        public void GetEconomy()
        {
            if( excelReader.ReadExcelFile_SetDataSet(excelFileName))
                excelReader.GetEconomy(programContext.Path);
            

        }
        [Test]
        public void Context_Open_Save()
        {
            if (excelReader.ReadExcelFile_SetDataSet(excelFileName))
            {
                string newPath = CStock.ProgramContext.PathBin;

                this.programContext.SetNewPath_ID(newPath, "test");
                //this.programContext.Delete();

                this.programContext.ProgramContext_OpenOrCreate(newPath, false);
                excelReader.GetEconomy(programContext.Path);
                this.programContext.Save();
            }
            //Assert.IsTrue(programContext.Serialize());
        }
        [Test]
        public void Context_Delete_Test()
        {
            excelReader.ReadExcelFile_SetDataSet(excelFileName);
            string newPath = CStock.ProgramContext.PathBin ;


            this.programContext.SetNewPath_ID(newPath, "testDelete");
            this.programContext.Delete();

        

        }
        [Test]
        public void ChangeEconomyPath_NewTest()
        {
            if (excelReader.ReadExcelFile_SetDataSet(excelFileName))
            {

                string newPath = ProgramContext.PathBin;

                this.programContext.SetNewPath_ID(newPath, "test222");


                Assert.IsNotNull(excelReader.GetEconomy(programContext.Path));

            }
        }
        [Test]
        public void CreateEconomy_NewTest_WithRandomShareData()
        {
            if (excelReader.ReadExcelFile_SetDataSet(excelFileName))
            {
                string myID = "NewTest";
                string myPath = CStock.ProgramContext.PathBin;


                this.programContext = CStock.ProgramContext.CreateProgramContext(myPath, myID, true);
                this.programContext.TradeEconomy.Empty_All();
                this.programContext.Delete();



                this.programContext.TradeEconomy = excelReader.GetEconomy(programContext.Path);

                excelReader.TradeEconomy.CreateShareData_FromDateStart(10);
                this.programContext.Serialize();
            }



        }
    
	}

	
}